<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>点击变色案例</title>
  <!-- <script src="../vue.js"></script> -->
  <style>
    .active {
      background-color: #f4f4f4;
    }
  </style>
</head>

<body>
  <div id="box">
    <ul>
      <li v-for="item,index in dataList" :class="current===index?'active':''" @click="handleClick(index)">
        {{item}}
      </li>
    </ul>
  </div>
  <script>
    let obj = {
      data() {
        return {
          dataList: ["第一个", "第二个", "第三个"],
          current: 0,
        };
      },
      methods: {
        handleClick(index) {
          this.current = index;
        },
      },
    };
    let app = Vue.createApp(obj).mount("#box");
  </script>
</body>

</html>